<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <div id="app"></div>
    <script src="../vuejs/vue.js"></script>
    <template id="my-app">
        <button @click="changeFullName">修改fullName</button>
        <h2>{{fullName}}</h2>

    </template>
    <script>
        Vue.createApp({
            template: `#my-app`,
            data() {
                return {
                    firstName: 'Kobe',
                    lastName: 'Bryant',
                    score: 80,
                    message: 'Hello World'
                }
            },
            computed: {
                // fullName的getter方法

                // fullName:function() {

                //     return this.firstName + " " + this.lastName;
                // },
                // fullName的完整写法
                fullName: {
                    get: function () {
                        return this.firstName + " " + this.lastName;
                    },
                    set: function (newData) {
                        console.log(newData);
                        let name=newData.split(" ");
                        this.firstName=name[0];
                        this.lastName=name[1];
                        
                    }
                }

            },
            methods: {

                changeFullName() {
                    this.fullName = 'coby new'
                }
            }

        }).mount('#app')
    </script>
</body>

</html>